version 2 of Scheduled Activities by John Clemens begins here. "An extension to allow scheduling of activities." [ Change Log: version 2 (July 19, 2006): Improved paragraph breaks between activities Added the new syntax: schedule now Added reporting conditions: if first current activity and if first similar activity Added the pending relation Added example "Bunnies" version 1 (July 15, 2006): Initial version Please report any bugs/suggestions to me at jdc20@psu.edu, or post them to rec.arts.int-fiction. ] Section 1 - Scheduling Rule Table of Scheduled Events Moment Turn Event Target Similar a time a number an activity a thing a number with 49 blank rows This is the scheduled events rule: check skipped events; change stored_preceding to 0; repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is time of day, let flag be 1; if there is a Turn entry and the Turn entry is turn count, let flag be 1; if flag is 1 begin; if there is a Similar entry and Similar entry is 1, change stored_preceding to 2; mark Event entry activities; if there is a Target entry, carry out the Event entry activity with the Target entry; otherwise carry out the Event entry activity; space lines; change stored_preceding to 1; blank out the whole row; end if; end repeat; change stored_preceding to 0. A procedural rule: move the scheduled events rule to before the timed events rule. Section 2 - Utility functions - unindexed The stored_preceding is a number that varies. The stored_preceding is 0. [ 0: first activity this turn, 1 : some activity precedes, 2: same activity precedes] To mark (E - activity) activities: repeat through the Table of Scheduled Events begin; if the Event entry is E, change the Similar entry to 1; end repeat. [ This adds a paragraph break, but only if something has been printed by the activity. ] To space lines: (- if (say__p) I7_DivideParagraph(); -) [ The next check is done to account for time advancements of more than one minute. ] To check skipped events: if no skipped events, rule succeeds; while skipped events begin; repeat through the Table of Scheduled Events in Moment order begin; if there is a Target entry, carry out the Event entry activity with the Target entry; otherwise carry out the Event entry activity; space lines; blank out the whole row; end repeat; end while. To decide if skipped events: repeat through the Table of Scheduled Events begin; if there is a Moment entry and the Moment entry is before the time of day, decide yes; end repeat; decide no. To decide if no skipped events: if skipped events, decide no; decide yes. Section 3 - Scheduling activities To schedule (E - activity) for (T - thing) at (M - time): if the number of blank rows in the Table of Scheduled Events is 0, rule succeeds; choose a blank row in the Table of Scheduled Events; change the Moment entry to M; change the Event entry to E; change the Target entry to T. To schedule (E - activity) at (M - time): if the number of blank rows in the Table of Scheduled Events is 0, rule succeeds; choose a blank row in the Table of Scheduled Events; change the Moment entry to M; change the Event entry to E. To schedule (event - activity) for (target - thing) in (n - number) minutes: schedule event for target at n minutes after the time of day. To schedule (event - activity) in (n - number) minutes: schedule event at n minutes after the time of day. To schedule (event - activity) for (target - thing) now: schedule event for target at the time of day. To schedule (event - activity) now: schedule event at the time of day. To schedule (E - activity) for (T - thing) in (d - number) turns: if the number of blank rows in the Table of Scheduled Events is 0, rule succeeds; choose a blank row in the Table of Scheduled Events; change the Turn entry to turn count + d; change the Event entry to E; change the Target entry to T. To schedule (E - activity) in (d - number) turns: if the number of blank rows in the Table of Scheduled Events is 0, rule succeeds; choose a blank row in the Table of Scheduled Events; change the Turn entry to turn count + d; change the Event entry to E; Section 4 - Canceling activities To cancel all scheduled events for (T - thing): repeat through the Table of Scheduled Events begin; if there is a Target entry and the Target entry is T, blank out the whole row; end repeat. To cancel all scheduled events: repeat through the Table of Scheduled Events begin; blank out the whole row; end repeat. To cancel next timed event for (T - thing): repeat through the Table of Scheduled Events in Moment order begin; if there is a Target entry and Target entry is T begin; blank out the whole row; rule succeeds; end if; end repeat. To cancel next timed event: repeat through the Table of Scheduled Events in Moment order begin; blank out the whole row; rule succeeds; end repeat. To cancel all scheduled (E - activity): repeat through the Table of Scheduled Events begin; if there is an Event entry and the Event entry is E, blank out the whole row; end repeat. To cancel all scheduled (E - activity) for (T - thing): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Target entry and the Target entry is T, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if flag is 2, blank out the whole row; end repeat. To cancel all scheduled events at (M - time): repeat through the Table of Scheduled Events begin; if there is a Moment entry and the Moment entry is M, blank out the whole row; end repeat. To cancel all scheduled events for (T - thing) at (M - time): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Target entry and the Target entry is T, increase flag by 1; if there is a Moment entry and the Moment entry is M, increase flag by 1; if flag is 2, blank out the whole row; end repeat. Section 5 - Checking scheduled activities To decide if there is an event scheduled: if the number of filled rows in the Table of Scheduled Events is 0, decide no; decide yes. To decide if there is an event scheduled for (T - thing): if there is a Target of T in the Table of Scheduled Events, decide yes; decide no. To decide if there is (E - activity) scheduled for (T - thing): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Target entry and the Target entry is T, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if flag is 2, decide yes; end repeat; decide no. To decide if there is (E - activity) scheduled: if there is an Event of E in the Table of Scheduled Events, decide yes; decide no. To decide if there is an event scheduled at (M - time): if there is a Moment of M in the Table of Scheduled Events, decide yes; decide no. To decide if there is an event scheduled for (T - thing) at (M - time): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Target entry and the Target entry is T, increase flag by 1; if there is a Moment entry and the Moment entry is M, increase flag by 1; if flag is 2, decide yes; end repeat; decide no. To decide if there is (E - activity) scheduled at (M - time): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is M, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if flag is 2, decide yes; end repeat; decide no. To decide if there is (E - activity) scheduled for (T - thing) at (M - time): repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Target entry and the Target entry is T, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if there is a Moment entry and the Moment entry is M, increase flag by 1; if flag is 3, decide yes; end repeat; decide no. To decide if there is an event scheduled now: repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is time of day, increase flag by 1; if there is a Turn entry and the Turn entry is turn count, increase flag by 1; if flag is 1, decide yes; end repeat; decide no. To decide if there is (E - activity) scheduled now: repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is time of day, increase flag by 1; if there is a Turn entry and the Turn entry is turn count, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if flag is 2, decide yes; end repeat; decide no. To decide if there is an event scheduled for (T - thing) now: repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is time of day, increase flag by 1; if there is a Turn entry and the Turn entry is turn count, increase flag by 1; if there is a Target entry and the Target entry is T, increase flag by 1; if flag is 2, decide yes; end repeat; decide no. To decide if there is (E - activity) scheduled for (T - thing) now: repeat through the Table of Scheduled Events begin; let flag be 0; if there is a Moment entry and the Moment entry is time of day, increase flag by 1; if there is a Turn entry and the Turn entry is turn count, increase flag by 1; if there is an Event entry and the Event entry is E, increase flag by 1; if there is a Target entry and the Target entry is T, increase flag by 1; if flag is 3, decide yes; end repeat; decide no. Section 6 - Reporting activities To decide if first current activity: if stored_preceding is 0, decide yes; decide no. To decide if first similar activity: if stored_preceding is 2, decide no; decide yes. Pending relates a thing (called T) to an activity (called E) when there is E scheduled for T now. The verb to be pending implies the pending relation. Scheduled Activities ends here. ---- DOCUMENTATION ---- This extension allows activities to be scheduled at absolute and relative times. These activities may later be checked or cancelled. The advantage of this over the standard events is that activities may take a variable, and the same activity may be scheduled multiple times. Rudimentary support is also provided for grouping output of multiple activities scheduled for the same turn. The extension stores events in a table called the Table of Scheduled Events. This table initially holds 50 future activities; if more storage is needed, you can add a table continuation as follows: Table of Scheduled Events (continued) Moment Turn Event Target a time a number an activity a thing with 100 blank rows A new rule (the scheduled events rule) is inserted before the timed events rule (which handles the usual timed events). So scheduled activities will occur immediately before events invoked with phrases like "the egg-timer clucks in four turns from now". SCHEDULING: The extension provides the following phrases to schedule activities: schedule (an activity) for (a thing) at (a time) schedule (an activity) at (a time) schedule (an activity) for (a thing) in (a number) minutes schedule (an activity) in (a number) minutes schedule (an activity) for (a thing) now schedule (an activity) now schedule (an activity) for (a thing) in (a number) turns schedule (an activity) in (a number) turns Here, "now" means at the end of the current turn. CANCELING: Activities can also be canceled: cancel all scheduled events for (a thing) cancel all scheduled events cancel next timed event for (a thing) cancel next timed event cancel all scheduled (an activity) cancel all scheduled (an activity) for (a thing) cancel all scheduled events at (a time) cancel all scheduled events for (a thing) at (a time) Note that "next timed event" considers only events scheduled in times, not those scheduled in turns. Also note that only activities scheduled with the phrases above can be canceled or checked in this way. CHECKING: The following conditions are supplied: if there is an event scheduled if there is an event scheduled for (a thing) if there is (an activity) scheduled for (a thing) if there is (an activity) scheduled if there is an event scheduled at (a time) if there is an event scheduled for (a thing) at (a time) if there is (an activity) scheduled at (a time) if there is (an activity) scheduled for (a thing) at (a time) if there is an event scheduled now if there is (an activity) scheduled now if there is an event scheduled for (a thing) now if there is (an activity) scheduled for (a thing) now REPORTING: Several conditions allow better reporting of multiple activities happening in the same turn. if first current activity This condition is true when carrying out the first scheduled activity during a given turn. if first similar activity This condition is true when carrying out a particular activity for the first time during a given turn (even if other activities have been carried out). This can be used to combine reports for carrying out the same activity with multiple things in the same turn; see the example "Bunnies". Note that these two conditions do not apply to skipped events caused by changing the time directly. A new relation, the pending relation, is defined between things and activities when the given activity is scheduled for the thing during the current turn. So, for instance, the condition if a rabbit is pending waking will be true if the waking activity is scheduled for some rabbit during the current turn. Example: * Tinitinitis - Scheduling, testing, and cancelling activities. "Tinitinitis" Include Scheduled Activities by John Clemens. The Concert Hall is a room. A percussive instrument is a kind of thing. A percussive instrument can be ringing. A percussive instrument has a number called duration. The duration of a percussive instrument is usually 5. The cymbal is a percussive instrument in the concert hall. The triangle is a percussive instrument in the concert hall. The duration of the triangle is 1. Striking is an action applying to one thing. Understand "strike [something]" as striking. Report striking: say "You strike [the noun]." Instead of striking a percussive instrument: if the noun is ringing, say "You strike [the noun] again[if there is silencing scheduled for the noun now], just in time[end if]."; otherwise say "You strike [the noun] and it starts ringing."; now the noun is ringing; cancel all scheduled silencing for the noun; schedule silencing for the noun in duration of noun minutes. Silencing something is an activity. Rule for silencing something (called bell): if the bell is ringing, say "[The bell] stops ringing."; now the bell is not ringing. Test me with "strike cymbal / strike cymbal / strike triangle / strike triangle / z / z / z". Example: ** Bunnies - Grouping activity reports. "Bunnies" Include version 2 of Scheduled Activities by John Clemens. When play begins, say "You have snuck into the castle to steal the King's scepter. You have heard tales of the fierce rabbits guarding the palace, but are armed with a supply of holy hand grenades." A mood is a kind of value. The moods are asleep, suspicious, vicious, and mutilated. Definition: a rabbit is living if it is not mutilated. To say long mood of (bugs - a rabbit): if bugs is asleep, say "sleeping peacefully"; if bugs is suspicious, say "eyeing you suspiciously"; if bugs is vicious, say "snarling viciously"; if bugs is mutilated, say "splattered on the walls". A rabbit is a kind of animal. A rabbit has a mood. A rabbit is usually asleep. Understand the mood property as describing a rabbit. The printed name of a rabbit is usually "[mood] rabbit". The printed plural name of a rabbit is usually "[mood] rabbits". Rule for printing the name of a rabbit (called bugs) while listing contents of a room: say "rabbit [long mood of item described]". Rule for printing the plural name of a rabbit while listing contents of a room: say "rabbits [long mood of item described]". Instead of doing something to a mutilated rabbit, say "There's really not much left of it." After going to somewhere: repeat with bugs running through rabbits in location begin; if bugs is asleep, schedule waking for bugs now; if bugs is suspicious, schedule angering for bugs now; end repeat; continue the action. Every turn when a vicious rabbit is in location: say "You are suddenly beset by sharp pointy teeth as [if the number of vicious rabbits in location > 1][the number of vicious rabbits in location in words] vicious rabbits lunge[otherwise]a vicious rabbit lunges[end if] for your throat."; end the game in death. [ Two variations on testing pending activities ] Definition: a rabbit is stirring if it is pending waking. Waking something is an activity. Rule for waking an asleep rabbit (called bugs): now bugs is suspicious; schedule angering for bugs in 1 turns; if first similar activity and a stirring rabbit is visible, say "Hearing you, the sleeping rabbit[if the number of visible rabbits which are stirring is 1] begins[otherwise]s begin[end if] to stir." Angering something is an activity. Rule for angering a suspicious rabbit (called bugs): now bugs is vicious; if first similar activity and a visible rabbit is pending angering, say "The suspicious rabbit[if the number of visible rabbits which are pending angering is 1] bares its[otherwise]s bare their[end if] teeth at you." A holy hand grenade is a kind of thing. The player carries five grenades. Definition: a thing is possessed if it is carried by the player. Understand "throw [possessed grenade] [direction]" as lobbing it toward. Understand the commands "lob" and "lobbeth" as "throw". Instead of dropping a grenade, try lobbing the noun toward down. Lobbing it toward is an action applying to one thing and one visible thing. Check lobbing it toward: abide by the can't drop what's not held rule. The target room is a room that varies. Carry out lobbing it toward: if there is exploding scheduled for the noun begin; say "You throw the grenade"; otherwise; say "You pull the pin and throw the grenade"; schedule exploding for the noun in 2 turns; end if; change the target room to the room second noun from location; if the second noun is down, change the target room to location; if target room is not a room begin; say " [second noun], where it bounces off [if second noun is up]the ceiling[otherwise]the wall[end if] and lands at your feet."; move noun to location; otherwise; if target room is location, say " on the ground."; otherwise say " into [the target room]."; move noun to target room; end if. Exploding something is an activity. Rule for exploding a grenade (called bomb): if bomb is in the location begin; say "[bold type]Boom! [roman type]The grenade explodes, killing you instantly."; cancel all scheduled events; end the game in death; otherwise; let destroyed be the location of bomb; if destroyed is a room begin; say "You hear an explosion from [the best route from location to the location of bomb][if a living rabbit is in the location of bomb], followed by the unmistakable sound of rabbit screams[end if]."; now every rabbit in the location of bomb is mutilated; [note that we do not need to cancel activities for the rabbits, since the activity rules don't apply to mutilated rabbits] repeat with item running through grenades in destroyed begin; cancel all scheduled events for item; remove item from play; end repeat; end if; end if. The Entrance is a room. "A Hall stretches to the east, and the exit is back west." The Hall is east of the entrance. "The entrance is west, and the banquet room is south." In the Hall are five rabbits. The Banquet Room is south of the hall. "The hall is north, and the throne room is west." In the Banquet Room are 3 rabbits and 1 suspicious rabbit. The Throne room is west of the banquet room. "The treasure is stored here." In the throne room are two vicious rabbits. The scepter is in the throne room. The description of the scepter is "Covered with jewels, and worth the risk." Instead of going west in the Entrance: say "Not without the scepter." Instead of going west in the Entrance when the player carries the scepter: say "You escape with the scepter, ensuring your fortune."; end the game in victory. Test me with "e / lobbeth holy hand grenade / w / z / e / throw grenade s / z / z / s / throw grenade w / z / z / w / take scepter / e / n / w / w". Test death with "e / s / n".